package com.gtw.observer;

import java.util.Vector;

public abstract class Subject {
    private Vector<Observer> observers = new Vector<Observer>();

    /**
     * 必须能够动态添加取消观察者
     */
    public void addObserver(Observer observer) {
        this.observers.add(observer);
    }

    public void delObserver(Observer observer) {
        this.observers.remove(observer);
    }

    /**
     * 被观察者必须实现的职责:通知观察者
     */
    public void notifyObserver(){
        for (Observer observer : this.observers){
            observer.update();
        }
    }
}
